// index.js
const util = require('../../utils/util')
const { IndexUrl, GoodsCount } = require('../../config/api')


Page({
  data: {
    newGoodsList: [],
    couponList: [],
    channel: [],
    grouponList: [],
    banner: [],
    brandList: [],
    hotGoodsList: [],
    topicList: [],
    floorGoodsList: [],
    goodsCount:0
  },

  getIndexData() {
    let that = this;
    util.request(IndexUrl).then(res => {
      let { errno, data } = res;
      if (errno == 0) {
        that.setData({
          newGoodsList: data.newGoodsList,
          couponList: data.couponList,
          channel: data.channel,
          grouponList: data.grouponList,
          banner: data.banner,
          brandList: data.brandList,
          hotGoodsList: data.hotGoodsList,
          topicList: data.topicList,
          floorGoodsList: data.floorGoodsList,
        })
      }
    })
    util.request(GoodsCount).then(res=>{
      that.setData({
        goodsCount:res.data.goodsCount
      })
    })
  },

 onLoad(){
   this.getIndexData()
 }
})
